<?php
/**
 * Created by PhpStorm.
 * User: HuangLuSen
 * Date: 2017/6/1
 * Time: 11:22
 */

namespace app\api\controller;


use app\common\traits\Wechat;
use EasyWeChat\Message\Location;
use GuzzleHttp\Client;
use think\Controller;

class Ertong extends  Controller
{
    use Wechat;

    public function index()
    {
//        self::getInstance()['config']->set('oauth.callback',url('api/ertong/getwechat','',true,true));
        self::getInstance()->oauth->redirect(url('api/ertong/getwechat','',true,true))->send(); //发起网页授权请求
    }
    public function getwechat(){
        $oauth = self::getInstance()->oauth;//获取微信回掉回来的东西
        $user = $oauth->user()->toArray();
//        $url = url('mobile/login/receive',['id'=>$user['id'],'headimgurl'=>$user['avatar']]);
//        $this->redirect("http://et.121314.com".$url);
        $str = <<<str
        <form style='display:none;' id='form1' name='form1' method='post' action='http://et.121314.com/mobile/login/receive.html'>
			  <input name='id' type='text' value="{$user['id']}" />
			  <input name='headimgurl' type='text' value="{$user['avatar']}"/>
			</form>
			<script type='text/javascript'>function load_submit(){document.form1.submit()}load_submit();</script>
str;
        echo $str;
    }
    /**
     *查看微信token
     */
    public function gettoken(){
        return self::getInstance()->access_token->getToken();
//        return 'abc';
    }

    /**
     *强制更新token
     */
    public function newtoken(){
        return self::getInstance()->access_token->getToken(true);
    }
}